package com.zxl.manager.privacy.utils.utils;

import android.content.Intent;

import java.net.URISyntaxException;
import java.util.ArrayList;

/**
 * Created by makai on 15-6-26.
 */
public class ConvertUtils {

	static public boolean int2boolean(int intValue) {
		return intValue != 0;
	}

	static public int boolean2int(boolean booleanValue) {
		if (booleanValue) {
			return 1;
		}
		return 0;
	}

	public static String intentToString(final Intent intent) {
		if (intent == null) {
			return null;
		}
		String returnStr = null;
		if (intent.getAction() == null || intent.getAction().equals("")) {
			intent.setAction(Intent.ACTION_VIEW);
		}
		try {
			returnStr = intent.toUri(0);
		} catch (Exception e) {
		} catch (Error e) {
		}
		return returnStr;
	}

	public static Intent stringToIntent(final String intentStr) {
		if (intentStr == null) {
			return null;
		}
		try {
			Intent intent = Intent.parseUri(intentStr, 0);
			return intent;
		} catch (URISyntaxException e) {
			// TODO LOG 创建Intent失败
			e.printStackTrace();
			return null;
		} catch (NumberFormatException e) {
			// TODO LOG 创建Intent失败
			e.printStackTrace();
			return null;
		} catch (Exception e) {
			// TODO LOG 创建Intent失败
			e.printStackTrace();
			return null;
		}
	}

	/**
	 * 将Integer类型的ArrayList转化为int数组
	 * @param intObjects
	 * @return
	 */
	public static int[] toIntArray(ArrayList<Integer> intObjects) {
		final int size = intObjects.size();
		final int[] array = new int[size];
		for (int i = 0; i < size; i++) {
			array[i] = intObjects.get(i).intValue();
		}
		return array;
	}
}
